package
{
	import component.button.MyButton;
	import component.menu.Menu;
	import component.menu.MenuEvent;
	import component.menu.data.MenuItemData;
	
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	
	import obecto.core.FLApplication;
	import obecto.event.FLEvent;

	[SWF(backgroundColor="0xCDCDCD")]
	public class MenuSample extends FLApplication
	{
		private var myButton : MyButton;
		private var myMenu : Menu;
		
		public function MenuSample()
		{
			super();
			
			stage.frameRate = 35;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			myButton = new MyButton();
			myButton.addEventListener(FLEvent.CREATION_COMPLETE, handleButtonCreationComplete);
			myButton.addEventListener(MouseEvent.CLICK, handleButtonClick);
			
			myMenu = new Menu();
			myMenu.addEventListener(FLEvent.CREATION_COMPLETE, handleMenuCreationComplete);
			myMenu.addEventListener(MenuEvent.SELECT, handleMenuItemSelect);
			myMenu.addEventListener(MenuEvent.DESELECT, handleMenuItemDeselect);
			myMenu.itemsData = [
				new MenuItemData("item1", false, { label: "Item 1", enabled: true }),
				new MenuItemData("item2", false, { label: "Item 2", enabled: true }),
				new MenuItemData("item3", false, { label: "Item 3", enabled: true }),
				new MenuItemData("item4", false, { label: "Item 4", enabled: true })];
		}
		
		private function handleButtonCreationComplete(e : FLEvent) : void 
		{
			myButton.x = 100;
			myButton.y = 60;
			
			myButton.label = "Show Menu";
			myButton.textField.textColor = myButton.textColor;
			
			addChild(myButton);
		}
		
		private function handleMenuCreationComplete(e : FLEvent) : void 
		{
			myMenu.x = 100;
			myMenu.y = 110;
			
			addChild(myMenu);
		}
		
		private function handleButtonClick(e : MouseEvent) : void 
		{
			if (myButton.label == "Show Menu")
			{
				myMenu.show();
				myButton.label = "Hide Menu";
			}
			else
			{
				myMenu.hide();
				myButton.label = "Show Menu";
			}
		}
		
		private function handleMenuItemSelect(e : MenuEvent) : void
		{
			trace("SELECT: " + e.itemData.id);
		}
		
		private function handleMenuItemDeselect(e : MenuEvent) : void 
		{
			trace("DESELECT: " + e.itemData.id);
		}
		
	}
}